package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SysUserControllerApi;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 包装类的默认值： null
 * int : 0
 * short : 0  (short enable=0)(Short enable = null)
 * boolean：false
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class SysUserController implements SysUserControllerApi {

    @Autowired
    UserService userService;

    @Override
    @PostMapping("/register")
    public Result<Long> register(SysRegisterDTO sysRegisterDTO) {
        Long userId = userService.register(sysRegisterDTO);
        return Result.success(userId);
    }

    /**
     * 根据用户名（手机号） 获取 userDTO对象
     * @param username
     * @return
     */
    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(@RequestParam("username") String username){
        SysUserDTO userDTO = userService.queryUser(username);
        return Result.success(userDTO);
    }

}
